﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using CRM.UTIL;

namespace CRM.DAL
{
        public class PartsImagesD : DBChannel
        {
            /// <summary>
            /// 可以在此选择数据库连接，默认为CRM
            /// </summary>
            public PartsImagesD() : base()
            {
            }


            #region 执行存储过程 Pro_GetPartsImages ,根据条件获取回馈信息

            /// <summary>
            /// 执行存储过程 Pro_GetPartsImages 
            ///xialei
            /// </summary>

            public DataTable ExecuteGetPartsImages(ref CRM.MODEL.PartsImages.GetPartsImages stu)
            {
                //存储过程参数	 		     
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.IDPARM, SqlDbType.Int));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.GUIDPARM, SqlDbType.VarChar));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.FILENAMEPARM,
                    SqlDbType.VarChar, 100));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.FILESIZEPARM,
                    SqlDbType.VarChar, 20));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.FILEPATHPARM,
                    SqlDbType.VarChar, 200));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.ISAVAILABLEPARM,
                    SqlDbType.Bit));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.CREATEBYPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.CREATETIMEPARM,
                    SqlDbType.DateTime));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.LASTMODIFYBYPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.LASTMODIFYTIMEPARM,
                    SqlDbType.DateTime));

                //分页参数
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.ORDERSTRING_PARM,
                    SqlDbType.VarChar, 1000));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.PAGESIZE_PARM,
                    SqlDbType.Int));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.CURRENTPAGEINDEX_PARM,
                    SqlDbType.Int));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.GetPartsImages.TOTALITEMS_PARM,
                    SqlDbType.Decimal));

                //设置参数的值
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.IDPARM].Value = stu.IDVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.GUIDPARM].Value = stu.GUIDVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.FILENAMEPARM].Value = stu.FILENAMEVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.FILESIZEPARM].Value = stu.FILESIZEVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.FILEPATHPARM].Value = stu.FILEPATHVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.ISAVAILABLEPARM].Value =
                    stu.ISAVAILABLEVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.CREATEBYPARM].Value = stu.CREATEBYVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.CREATETIMEPARM].Value = stu.CREATETIMEVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.LASTMODIFYBYPARM].Value =
                    stu.LASTMODIFYBYVALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.LASTMODIFYTIMEPARM].Value =
                    stu.LASTMODIFYTIMEVALUE;

                //设置分页参数的值
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.ORDERSTRING_PARM].Value =
                    stu.ORDERSTRING_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.PAGESIZE_PARM].Value = stu.PAGESIZE_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.CURRENTPAGEINDEX_PARM].Value =
                    stu.CURRENTPAGEINDEX_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.TOTALITEMS_PARM].Value =
                    stu.TOTALITEMS_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.TOTALITEMS_PARM].Direction =
                    ParameterDirection.Output;

                //执行
                DataTable dt = this.GetDataByProcedure("dbo.Pro_GetPartsImages");
                //获取数据库的信息
                stu.TOTALITEMS_VALUE =
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.GetPartsImages.TOTALITEMS_PARM].Value;

                return dt;
            }

            #endregion

            #region 执行存储过程 Pro_EditPartsImages,根据条件获取回馈信息

            /// <summary>
            /// 执行存储过程 Pro_EditPartsImages 的相关参数
            ///xialei
            /// </summary>
            public int ExecuteEditPartsImages(ref CRM.MODEL.PartsImages.EditPartsImages stu)
            {
                if ((string) stu.ACTION_VALUE == "Update")
                {
                    #region Update

                    var sqlSb = new StringBuilder();
                    sqlCmd.Parameters.Clear();
                    sqlSb.Append(" UPDATE PartsImages SET ");

                    if (stu.ID_VALUE != DBNull.Value)
                    {
                    }
                    if (stu.GUID_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" Guid=@Guid,");
                        sqlCmd.Parameters.Add(new SqlParameter("@GUID", stu.GUID_VALUE));
                    }
                    if (stu.FILENAME_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" FileName=@FileName,");
                        sqlCmd.Parameters.Add(new SqlParameter("@FILENAME", stu.FILENAME_VALUE));
                    }
                    if (stu.FILESIZE_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" FileSize=@FileSize,");
                        sqlCmd.Parameters.Add(new SqlParameter("@FILESIZE", stu.FILESIZE_VALUE));
                    }
                    if (stu.FILEPATH_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" FilePath=@FilePath,");
                        sqlCmd.Parameters.Add(new SqlParameter("@FILEPATH", stu.FILEPATH_VALUE));
                    }
                    if (stu.ISAVAILABLE_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" IsAvailable=@IsAvailable,");
                        sqlCmd.Parameters.Add(new SqlParameter("@ISAVAILABLE", stu.ISAVAILABLE_VALUE));
                    }
                    if (stu.CREATEBY_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" CreateBy=@CreateBy,");
                        sqlCmd.Parameters.Add(new SqlParameter("@CREATEBY", stu.CREATEBY_VALUE));
                    }
                    if (stu.CREATETIME_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" CreateTime=@CreateTime,");
                        sqlCmd.Parameters.Add(new SqlParameter("@CREATETIME", stu.CREATETIME_VALUE));
                    }
                    if (stu.LASTMODIFYBY_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" LastModifyBy=@LastModifyBy,");
                        sqlCmd.Parameters.Add(new SqlParameter("@LASTMODIFYBY", stu.LASTMODIFYBY_VALUE));
                    }
                    if (stu.LASTMODIFYTIME_VALUE != DBNull.Value)
                    {

                        sqlSb.Append(" LastModifyTime=@LastModifyTime,");
                        sqlCmd.Parameters.Add(new SqlParameter("@LASTMODIFYTIME", stu.LASTMODIFYTIME_VALUE));
                    }

                    var sql = sqlSb.ToString().TrimEnd(',');

                    sqlCmd.Parameters.Add(new SqlParameter("@ID", stu.ID_VALUE));
                    //sqlCmd.CommandText = sqlSb.ToString();
                    //sqlCmd.ExecuteNonQuery();
                    int i = base.ExecuteSQL(sql + " WHERE ID=@ID");

                    return i;

                    #endregion
                }
                else
                {
                    //动作参数
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.ACTION_PARM,
                        SqlDbType.VarChar, 20));
                    //错误信息参数
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.ERRMSG_PARM,
                        SqlDbType.VarChar, 100));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.OUTID_PARM,
                        SqlDbType.Int));
                    ////表字段参数
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.IDPARM, SqlDbType.Int));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.GUIDPARM,
                        SqlDbType.VarChar));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.FILENAMEPARM,
                        SqlDbType.VarChar, 100));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.FILESIZEPARM,
                        SqlDbType.VarChar, 20));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.FILEPATHPARM,
                        SqlDbType.VarChar, 200));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.ISAVAILABLEPARM,
                        SqlDbType.Bit));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.CREATEBYPARM,
                        SqlDbType.VarChar, 50));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.CREATETIMEPARM,
                        SqlDbType.DateTime));
                    this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.PartsImages.EditPartsImages.LASTMODIFYBYPARM,
                        SqlDbType.VarChar, 50));
                    this.sqlCmd.Parameters.Add(new SqlParameter(
                        CRM.MODEL.PartsImages.EditPartsImages.LASTMODIFYTIMEPARM, SqlDbType.DateTime));



                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.ACTION_PARM].Value = stu.ACTION_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.ERRMSG_PARM].Direction =
                        ParameterDirection.Output;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.OUTID_PARM].Direction =
                        ParameterDirection.Output;
                    //设置参数的值
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.IDPARM].Value = stu.ID_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.GUIDPARM].Value = stu.GUID_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.FILENAMEPARM].Value =
                        stu.FILENAME_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.FILESIZEPARM].Value =
                        stu.FILESIZE_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.FILEPATHPARM].Value =
                        stu.FILEPATH_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.ISAVAILABLEPARM].Value =
                        stu.ISAVAILABLE_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.CREATEBYPARM].Value =
                        stu.CREATEBY_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.CREATETIMEPARM].Value =
                        stu.CREATETIME_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.LASTMODIFYBYPARM].Value =
                        stu.LASTMODIFYBY_VALUE;
                    this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.LASTMODIFYTIMEPARM].Value =
                        stu.LASTMODIFYTIME_VALUE;

                    int i = this.ExecuteProcedure("dbo.Pro_EditPartsImages"); //执行	
                    //获取数据库的信息
                    stu.ERRMSG_VALUE = this.sqlCmd.Parameters[CRM.MODEL.PartsImages.EditPartsImages.ERRMSG_PARM].Value;
                    return i;
                }
            }

            #endregion
        }
    
}
